/*LICENSE_BEGIN
 * ******************************************************************
 * All original parts of SoccerScope2003 have copyright (2003) by
 * Team YowAI, represented by Mr. Shuhei Shiota
 * The Department of Creative Informatics
 * The Graduate School of Information Science and Technology
 * The University of Tokyo
 * 
 * Additional classes (except libraries in /lib) were developed by 
 * the Dainamite Robocup-Team of the DAI-Labor, TU-Berlin 
 * (www.dai-labor.de)
 * 
 * Extended/new classes/packages are:
 *   soccerscope.analyzer.LogfileAnalyzer
 *   soccerscope.daistatistic.*
 *   soccerscope.daistatistic.charts.*
 *   soccerscope.daistatistic.tools.*
 *   soccerscope.db.*
 *   soccerscope.dialog.*
 *   soccerscope.model.PlayerWorldModel
 *   soccerscope.model.SimplePlayer
 *   soccerscope.net.AgentConnector
 *   soccerscope.training.*
 *   soccerscope.training.conditions.*
 * ******************************************************************
LICENSE_END*/
package soccerscope.view.layer;

import java.awt.Color;
import java.awt.Graphics;

import soccerscope.model.ClientScene;
import soccerscope.model.Param;
import soccerscope.util.geom.Point2f;
import soccerscope.view.FieldPane;

public class VelocityLayer extends Layer {

	public VelocityLayer(FieldPane fieldPane, boolean enable) {
		super(fieldPane, enable);
	}

	@Override
	public String getLayerName() {
		return "Velocity";
	}

	private Point2f nextPos = new Point2f();

	private Point2f accPos = new Point2f();

	@Override
	public void draw(Graphics g) {
		if (!this.enable)
			return;

		ClientScene clientScene = this.fieldPane.getScene();
		float ballMagnify = this.fieldPane.getBallMagnify();
		float playerMagnify = this.fieldPane.getPlayerMagnify();
		// draw ball velocity
		if (clientScene.ball.isEnable()) {

			float ballR = Param.BALL_SIZE * ballMagnify;

			g.setColor(Color.red);
			this.nextPos.add(clientScene.ball.pos, clientScene.ball.vel);
			drawLine(g, clientScene.ball.pos, this.nextPos);
			drawCircle(g, this.nextPos, ballR);
			if (clientScene.ball.acc.x != 0.0f
					|| clientScene.ball.acc.y != 0.0f) {
				g.setColor(Color.white);
				this.accPos.add(this.nextPos, clientScene.ball.acc);
				drawLine(g, this.nextPos, this.accPos);
				drawCircle(g, this.accPos, ballR);
			}
		}

		// draw player velocity
		for (int i = 0; i < Param.MAX_PLAYER * 2; i++) {
			if (!clientScene.player[i].isEnable())
				continue;

			float playerR = clientScene.player[i].getSize() * playerMagnify;
			Color drawColor = clientScene.player[i].getColor();

			g.setColor(Color.red);
			this.nextPos.add(clientScene.player[i].pos,
					clientScene.player[i].vel);
			drawLine(g, clientScene.player[i].pos, this.nextPos);
			drawCircle(g, this.nextPos, playerR);
			if (clientScene.player[i].acc.x != 0.0f
					|| clientScene.player[i].acc.y != 0.0f) {
				g.setColor(Color.white);
				this.accPos.add(this.nextPos, clientScene.player[i].acc);
				drawLine(g, this.nextPos, this.accPos);
				drawCircle(g, this.accPos, playerR);
			}
		}
	}
}
